static gboolean opt_quiet;
static gboolean opt_delete;
+static gboolean opt_add_tombstones;
static GOptionEntry options[] = {
+ { "add-tombstones", 0, 0, G_OPTION_ARG_NONE, &opt_add_tombstones, "Add tombstones for missing commits", NULL },
{ "quiet", 'q', 0, G_OPTION_ARG_NONE, &opt_quiet, "Only print error messages", NULL },
{ "delete", 0, 0, G_OPTION_ARG_NONE, &opt_delete, "Remove corrupted objects", NULL },
{ NULL }
guint n_partial = 0;
g_autoptr(GHashTable) objects = NULL;
g_autoptr(GHashTable) commits = NULL;
-
+ g_autoptr(GPtrArray) tombstones = NULL;
context = g_option_context_new ("- Check the repository for consistency");
if (!ostree_option_context_parse (context, options, &argc, &argv, OSTREE_BUILTIN_FLAG_NONE, &repo, cancellable, error))
g_hash_table_iter_init (&hash_iter, objects);
+ if (opt_add_tombstones)
+ tombstones = g_ptr_array_new_with_free_func (g_free);
+
while (g_hash_table_iter_next (&hash_iter, &key, &value))
{
GVariant *serialized_key = key;
if (commitstate & OSTREE_REPO_COMMIT_STATE_PARTIAL)
{
n_partial++;
+
+ if (opt_add_tombstones)
+ g_ptr_array_add (tombstones, g_strdup (checksum));
}
else
g_hash_table_insert (commits, g_variant_ref (serialized_key), serialized_key);
cancellable, error))
goto out;
- if (n_partial > 0)
+ if (opt_add_tombstones)
+ {
+ guint i;
+ if (tombstones->len)
+ {
+ GError *temp_error = NULL;
+ gboolean tombstone_commits = FALSE;
+ GKeyFile *config = ostree_repo_get_config (repo);
+ tombstone_commits = g_key_file_get_boolean (config, "core", "tombstone-commits", &temp_error);
+ /* tombstone_commits is FALSE either if it is not found or it is really set to FALSE in the config file. */
+ if (!tombstone_commits)
+ {
+ g_clear_error (&temp_error);
+ g_key_file_set_boolean (config, "core", "tombstone-commits", TRUE);
+ if (!ostree_repo_write_config (repo, config, error))
+ goto out;
+ }
+ }
+ for (i = 0; i < tombstones->len; i++)
+ {
+ const char *checksum = tombstones->pdata[i];
+ g_print ("Adding tombstone for commit %s\n", checksum);
+ if (!ostree_repo_delete_object (repo, OSTREE_OBJECT_TYPE_COMMIT, checksum, cancellable, error))
+ goto out;
+ }
+ }
+ else if (n_partial > 0)
{
g_print ("%u partial commits not verified\n", n_partial);
}